package me.evis.mobile.sms2cal.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import me.evis.mobile.sms2cal.parser.Util;

public class CalEvent {
    
    /**
     * Internal use.
     */
    public int id;
    
    public SmsData sourceSms;
    
    /**
     * This property defines a short summary or subject for the calendar
     * component.
     */
    public String summary;
    /**
     * The property defines the intended venue for the activity defined by a
     * calendar component.
     */
    public String location;
    /**
     * The property indicates the date/time that the instance of the iCalendar
     * object was created.
     */
    public Date dtStamp;
    /**
     * This property specifies when the calendar component begins.
     */
    public Date dtStart;
    /**
     * This property specifies the date and time that a calendar component ends.
     */
    public Date dtEnd;
    /**
     * This property provides a more complete description of the calendar
     * component, than that provided by the "SUMMARY" property.
     */
    public String description;
    /**
     * This property defines the access classification for calendar component.
     * "PUBLIC" / "PRIVATE" / "CONFIDENTIAL"
     */
    public String classification;
    /**
     * Some possible English values for CATEGORIES property include
     * "ANNIVERSARY", "APPOINTMENT", "BUSINESS", "EDUCATION", "HOLIDAY",
     * "MEETING", "MISCELLANEOUS", "NON-WORKING HOURS", "NOT IN OFFICE",
     * "PERSONAL", "PHONE CALL", "SICK DAY", "SPECIAL OCCASION", "TRAVEL",
     * "VACATION". Categories can be specified in any registered language.
     */
    public String categories;
    
    /**
     * Alarms.
     */
    private List<CalAlarm> calAlarms = new ArrayList<CalAlarm>();
    
    public void addCalAlarm(CalAlarm calAlarm) {
        calAlarms.add(calAlarm);
    }
    
    public List<CalAlarm> getCalAlarms() {
        return calAlarms;
    }
    
    public String toVEVENT() {
        StringBuffer sb = new StringBuffer();
        sb.append("BEGIN:VEVENT").append(Util.NL);
        sb.append("UID:").append(Util.getCalEventUid(dtStamp)).append(Util.NL);
        sb.append("SUMMARY:").append(summary).append(Util.NL);
        sb.append("LOCATION:").append(location).append(Util.NL);
        sb.append("DTSTAMP:").append(Util.getDateTimeDefaultFormat(dtStamp)).append(Util.NL);
        sb.append("DTSTART:").append(Util.getDateTimeDefaultFormat(dtStart)).append(Util.NL);
        sb.append("DTEND:").append(Util.getDateTimeDefaultFormat(dtEnd)).append(Util.NL);
        sb.append("DESCRIPTION:").append(description).append(Util.NL);
        sb.append("CLASS:").append(classification).append(Util.NL);
        sb.append("CATEGORIES:").append(categories).append(Util.NL);
        for (CalAlarm calAlarm : calAlarms) {
            sb.append(calAlarm.toVALARM());
        }
        sb.append("END:VEVENT").append(Util.NL);
        return sb.toString();
    }
}
